//
//  SCoreData.h
//  STool
//
//  Created by banggo on 15/7/13.
//
//

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface SCoreData : NSObject

/**
 *  数据库操作时间记录
 */
@property (nonatomic,assign)NSTimeInterval timeRecord;

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;




/**
 *  表名称
 */
@property (nonatomic, copy) NSString *tableName;
/**
 *  数据库名称
 */
@property (nonatomic, copy) NSString *databaseName;
/**
 *  设置表名和数据库名称 tableName表名 databaseName数据库名
 */
- (instancetype)setTableName:(NSString *)tableName andDatabaseName:(NSString*)databaseName;
/**
 *  初始化
 */
+ (id)sharedInstance;
/**
 *  插入数据(多条件检索) dictionary:需要插入的字典数据 key:需要检查的参数(nil即为无检查参数)
 */
- (BOOL)insertCoreData:(NSDictionary*)dictionary andKey:(NSString*)key,...NS_REQUIRES_NIL_TERMINATION;
#pragma mark - 主线程操作
/**
 *  查询全部数据(无条件检索) pageSize:每页数量 currentPage:第几页
 */
- (NSMutableArray*)selectData:(int)pageSize
                    andOffset:(int)currentPage
             andCompositorKey:(NSString*)compostinStr;
/**
 *  查询－特定参数(分页) pageSize:每页数量 currentPage:第几页 ids key－Value，key－Value
 */
- (NSMutableArray*)selectDataWithPageSize:(int)pageSize
                           andCurrentPage:(int)currentPage
                         andCompositorKey:(NSString*)compostinStr
                           andKeyAndValue:(id)ids,...NS_REQUIRES_NIL_TERMINATION;
/**
 *  查询－特定参数（偏移量） pageSize:每次数量 offset:偏移量
 */
- (NSMutableArray*)selectDataWithPageSize:(int)pageSize
                               andOffsets:(int)offset
                         andCompositorKey:(NSString*)compostinStr
                           andKeyAndValue:(id)ids,...NS_REQUIRES_NIL_TERMINATION;

/**
 *  删除所有数据(多条件检索)
 */
-(BOOL)deleteDataWithKeyAndValue:(id)ids,...NS_REQUIRES_NIL_TERMINATION;
/**
 *  更新数据(单一检索条件) mainKey:需要更新数据的主键 mainValue:需要更新数据的主键数据 dictionary:需要更新的字典
 */
- (BOOL)upDataMainKey:(NSString*)mainKey
            mainValue:(NSString*)mainValue
  andUpDataDictionary:(NSMutableDictionary*)dictionary;
/**
 *  更新数据(单一检索条件) mainKey需要更新数据的主键 mainValue需要更新数据的主键数据 ids需要更新的数据的key和Value
 */
- (BOOL)upDataMainKey:(NSString*)mainKey
            mainValue:(NSString*)mainValue
 andUpDataKeyAndValue:(id)ids,...NS_REQUIRES_NIL_TERMINATION;
/**
 *  更新数据(多条件检索) dictionary:需要更新的字典 ids:需要检索的keyValue条件
 */
- (BOOL)upDataDictionary:(NSMutableDictionary*)dictionary
    andUpDataKeyAndValue:(id)ids,...NS_REQUIRES_NIL_TERMINATION;
/**
 *  获取数据库长度
 */
- (NSUInteger)getDataCount;
#pragma mark - 子线程操作
@end
